<?php defined('SYSPATH') OR die('No direct access allowed.');

set_time_limit(360);

function money($key){
	return number_format($key, 0, '.', ' ').'р.';
}

function formula($key){ 
/* 	$first_price = $key->it_first_price;
	$it_shop_price = $key->it_shop_price;
	return $it_shop_price - (($it_shop_price - $first_price)/100*25); */
	return $key->it_internet_price;
}

function getKeyWords($words){  
	return ','.str_replace(' ', ',', $words);
}

define('TITLE_SHOP', 'C-NET');
define('DATE_FORMAT', 'd.m.Y');
define('DATE_FORMAT_DB', '%d.%m.%Y');
define('FILE_PRISE', 'C:/manual.chm');
define('MAIL_SUPPORT', 'support@c-net-shopping.ru');
define('MAIL_ADMIN', 'ivan.chura@webnizer.com');
define('MAIL_MARKET', 'koshkiny@mail.ru');

define('SERVER_PATH', '/home/webnizer/public_html/c-net/');
define('SERVER_SITE', 'baza.ru');

define('PATH_IMG', '/home/webnizer/c-net/Koshkin/img/');
define('PATH_HTML', '/home/webnizer/c-net/Koshkin/html/');
define('PATH_HTML_IMG', '/home/webnizer/c-net/Koshkin/html_img/'); 
define('PATH_ORDER', '/home/webnizer/c-net/Koshkin/orders/');

define('PATH_BAZA', '/home/webnizer/c-net/baza/');

header('X-Powered-By: ASP.NET'); 
header("ETag: PUB" . time());
header("Last-Modified: " . gmdate("D, d M Y H:i:s", time()-10) . " GMT");
header("Expires: " . gmdate("D, d M Y H:i:s", time() + 5) . " GMT");
header("Pragma: no-cache");
header("Cache-Control: max-age=1, s-maxage=1, no-cache, must-revalidate");

abstract class Web_Controller extends Template_Controller {
	
	var $groups = null;
	
	public function __construct()
	{	 
		
		parent::__construct();
		 
		Kohana::config_set('locale', 'ru_RU');
		
		$this->input = new Input();
 
		$this->session = new Session;
		
		if(count($this->session->get('items')) == 0){
			$this->session->set('items', array());
		}
		 
		if(($this->session->get('locale')) == null){
			$this->session->set('locale', 'ru_RU');
		}   
 
		$this->db = new Database; 

		$table = 'bz_groups';
 
		$this->groups = $this->db->select('*')->from($table)->orderby('gr_sorting')->orderby('gr_title')->get(); 
		
		$this->template->groups = $this->groups;
		$this->selected_page = null;
		
		$val = $this->session->get('items');
		if(empty($val)){
			$this->count_bin_items = 0;
		}else{
			$this->count_bin_items = count($val);
		}

                if (is_array($val) && count($val)) {
                    $archive_items = $this->db->select('*')->from('bz_items')->where('it_archive = 1')->in('it_id', array_keys($val))->get()->count();
                    if ($archive_items) {
                            $this->session->set('items', array());
                            url::redirect('?catalog_updated');
                    };
                }
 
	}
}

?>